<?php
/**
 * Created by PhpStorm.
 * User: Duck
 * Create time: 2016/12/21 9:56
 */

namespace D\Controller;
use Think\Controller;

class LoginController extends Controller{
    public function _initialize(){
        session('[start]');
    }
    public function login(){
        $this->display();
    }
    public function doLogin(){
        $type=I('post.types');
        $where=[
            'mtel'=>I('post.mtel'),
            'pwd'=>I('post.pwd'),
        ];
        $res=M($type)
                    ->join('roles ON '.$type.'.role_id = roles.role_id')
                    ->where($where)
                    ->find();
        if($res){
                session('[start]');
               $_SESSION['name']=$res['nick'].$res['role_name'];
                session('roleType',$res['menu_ids']);
                $a=substr($type,0,-1);
                $a=$a.'_id';
                session('id',$res[$a]);
                session('type',$type);
            $url=U('Index/index');
            header('Location:'.$url);
        }else{
           $url=U('Index/errorLogin');
            header('Location:'.$url);
        }
    }
    public function logout(){
        session(null);
        $url=U('Index/index');
        header('Location:'.$url);
    }
}